﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Player.Admin
{
    public partial class admindesc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //刷新用户信息
                SeleAllUser();
                //修改信息框展示
                if (Request.QueryString["upid"] != null)
                {
                    int upid = Convert.ToInt32(Request.QueryString["upid"]);
                    this.pl_deleupda.Visible = false;
                    this.Pl_update.Visible = true;
                    this.lbl_pltitle.Text = "修改信息";
                    //获取用户信息
                    List<Users> ls = BLL.UsersManage.SeleIdUsers(upid);
                    //给相应的内容赋值
                    this.lbl_pl2usid.Text = ls[0].Us_Id.ToString();
                    this.txt_pl2name.Text = ls[0].Us_Name;
                    this.txt_pl2account.Text = ls[0].Us_Account;
                    this.txt_pl2pwd.Text = ls[0].Us_Password;
                    this.txt_pl2price.Text = ls[0].Us_Balance.ToString();
                    this.txt_pl2goid.Text = ls[0].Us_Goid.ToString();
                    this.txt_pl2phone.Text = ls[0].Us_Phone;
                    char sex = ls[0].Us_Sex;
                    if (sex == '男')
                    {
                        this.rado_pl2nan.Checked = true;
                    }
                    else
                    {
                        this.rado_pl2nu.Checked = true;
                    }
                }
                //删除
                if (Request.QueryString["deid"] != null)
                {
                    this.pl_delete.Visible = true;
                }
            }

           
        }

        //保存修改信息
        protected void pl2_upbaocun(object sender, EventArgs e)
        {
            //获取输入内容并保存到Users类中
            char sex = '男';
            if (this.rado_pl2nu.Checked==true)
            {
                sex='女';
            }
            Users us = new Users();
            us.Us_Id = Convert.ToInt32(this.lbl_pl2usid.Text);
            us.Us_Name = this.txt_pl2name.Text.Trim();
            us.Us_Sex = sex;
            us.Us_Account= this.txt_pl2account.Text.Trim();
            us.Us_Password= this.txt_pl2pwd.Text.Trim();
            us.Us_Phone= this.txt_pl2phone.Text.Trim();
            us.Us_Balance = Convert.ToDouble(this.txt_pl2price.Text.Trim());
            us.Us_Goid=Convert.ToInt32(this.txt_pl2goid.Text.Trim());
            //执行修改
            bool pd=BLL.UsersManage.UpdaPartUsers(us);
            if (pd)
            {
                this.lbl_pl2bcts.Text = "保存成功";
                //刷新用户信息表
                SeleAllUser();
            }
            else
            {
                this.lbl_pl2bcts.Text = "保存失败";
            }
        }

        //修改信息框隐藏
        protected void btn_pl2gb_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
        }

        //刷新用户信息表
        private void SeleAllUser()
        {
            this.rptuser.DataSource = BLL.UsersManage.SeleAllUsers();
            this.rptuser.DataBind();
        }

        //添加信息框显示
        protected void btn_add_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
            this.pl_deleupda.Visible = true;
            this.lbl_pltitle.Text = "添加信息";
        }

        //添加信息框隐藏
        protected void btn_plgb_Click(object sender, EventArgs e)
        {
            this.pl_deleupda.Visible = false;
        }

        //保存添加信息
        protected void txt_plctrls_Click(object sender, EventArgs e)
        {
            //获取输入内容
            string name = this.txt_plname.Text.Trim();
            string sex = "";
            if (this.rado_plnan.Checked == true)
            {
                sex = "男";
            }
            else if (this.rado_plnu.Checked == true)
            {
                sex = "女";
            }
            string account = this.txt_placcont.Text.Trim();
            string password = this.txt_plpswd.Text.Trim();
            string phone = this.txt_plphnoe.Text.Trim();
            //非空验证
            if (name == String.Empty || sex == String.Empty || account == String.Empty || password == String.Empty || phone == String.Empty)
            {
                return;
            }
            //保存变量
            Users us = new Users();
            us.Us_Name = name;
            us.Us_Sex = Convert.ToChar(sex);
            us.Us_Account = account;
            us.Us_Password = password;
            us.Us_Phone = phone;
            //执行新增
            bool pd= BLL.UsersManage.AddUsers(us);
            if (pd)
            {
                this.lbl_pl1bcts.Text = "保存成功";
                //刷新用户信息
                SeleAllUser();
            }
            else
            {
                this.lbl_pl1bcts.Text = "保存失败";
            }
        }

        //删除提示框隐藏
        protected void btn_delequxiao_Click(object sender, EventArgs e)
        {
            this.pl_delete.Visible = false;
        }

        //确认删除
        protected void btn_delequedin_Click(object sender, EventArgs e)
        {
            this.pl_delete.Visible = true;
            int usid = Convert.ToInt32(Request.QueryString["deid"]);
            bool bl2 = BLL.OrdersManage.DeleUsidOrders(usid);
            bool bl3 = BLL.CommentsManage.DeleUsidComments(usid);
            bool bl1 = BLL.UsersManage.DeleUsers(usid);
            if (bl1)
            {
                this.pl_delete.Visible = false;
                //刷新用户信息
                SeleAllUser();
            }
        }

        //刷新
        protected void imgbtnsx_Click(object sender, ImageClickEventArgs e)
        {
            //刷新用户信息
            SeleAllUser();
        }

        //查询
        protected void imgbtn_Click(object sender, ImageClickEventArgs e)
        {
            //获取输入内容
            string name = this.txt_name.Text.Trim();
            //判断是否输入
            if (name == "")
            {
                this.lbl_ChaXunTiShi.Text = "请输入查询内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            //查询
            List<Users> ls = BLL.UsersManage.SeleNameUsers(name);
            if (ls.Count == 0)
            {
                this.lbl_ChaXunTiShi.Text = "未找到相关内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            this.lbl_ChaXunTiShi.Text = "";
            this.img_weizhaodao.Visible = false;
            this.rptuser.DataSource = ls;
            this.rptuser.DataBind();
        }

        

        

        
    }
}